#version 450 core

in vec2 fragPos;

uniform sampler2D uColorTexture;
uniform float uSize;
uniform float uHorizontalWidth;
uniform float uVerticalWidth;
uniform float uAspectRatio;

layout(location = 0) out vec4 color;


void main() {
    vec4 pixel = texelFetch(uColorTexture, ivec2(gl_FragCoord.xy), 0);

    float scaledY = fragPos.y;
    float scaledX = fragPos.x * uAspectRatio;

    bool isInBox = scaledY >= -uSize && scaledY <= uSize && scaledX >= -uSize && scaledX <= uSize;

    float crosshairHorizontalWidth = uSize * uHorizontalWidth;
    float crosshairVerticalWidth = uSize * uVerticalWidth;

    bool isInHorizontalCross = scaledY >= -crosshairHorizontalWidth && scaledY <= crosshairHorizontalWidth;
    bool isinVerticalCross = scaledX >= -crosshairVerticalWidth && scaledX <= crosshairVerticalWidth;
    bool shouldInvert = isInBox && (isInHorizontalCross || isinVerticalCross);

    int t = int(shouldInvert);
    vec3 invertedColor = t * (vec3(1) - pixel.xyz * 0.5f);
    vec3 normalCoplor = (1 - t) * pixel.xyz;
    color = vec4(invertedColor + normalCoplor, pixel.w);
}
